A. Field of the Invention
The present invention relates to a method for image processing, especially to a method for real-time auto-cropping a scanned image without performing the process of prescan.
B. Description of the Prior Art
The method of auto-cropping an image is a technology for selectively reading a scanned image from a background image which is usually black. According to current technology, the technology of auto-cropping an image must be performed after the process of prescan because the crop range of the scanned image cannot be determined beforehand. The function of image auto-crop can be provided by either a non-user interface scan (Non-UI Scan) or a user interface scan (UI Scan). The xe2x80x9cUI Scanxe2x80x9d here refers to a xe2x80x9cTWAIN user interfacexe2x80x9d in the TWAIN module. And the xe2x80x9cnon-UI Scanxe2x80x9d refers to a xe2x80x9cUser Interface not in the TWAIN modulexe2x80x9d. In either a non-UI scan or a UI scan, the prescan process must be performed first. Then, each pixel of the pre-scanned image is evaluated according to its R (Red) G (Green) B (Blue) values, thereby to determine the actual crop range for the scanned image. After determining the crop range, the scanner will be reset to read the image defined by the crop range and then discard the rest image. Or, the user may manually select the area of interest from the scanned image.
The disadvantages of the conventional technology is that the time and resources required for image auto-cropping is always the same regardless of the size of the desired image. It is because a prescan process is always required. If the area of interest is very small, most prescanned image transmitted from the scanner is useless while still consumes the same sources for processing. For instance, the time required for scanning an image of A3 size is the same as scanning a 3xc3x975 photo because the scanner must perform a prescan of an A3 image in color mode first. For non-user interface scan, the process would be more complicated. First, the crop range of the 3xc3x975 photo can only be obtained by computing its coordinates following a computation algorithm. Then, based on the crop range, the scanner will be reset to locate on the position of the 3xc3x975 photo and then enabled to perform a second image reading to get the image of the area of interest.
Accordingly, it is an object of the present invention to provide a method for real-time image auto-cropping, which can determine the crop range in read-time while reading the desired image data, thereby to efficiently crop the desired image without the process of prescan.
It is another object of the present invention to provide a method for real-time image auto-cropping, which can directly read the image data of the area of interest without having to transfer useless image data from the scanner, thereby to reduce the scanning time and process time.
In accordance with the invention, the method of the invention involves in finding the width and length of a scanned image in real time and then write the length and width into the header of a bitmap file as soon as the bottom line is found for a non-UI access. On the other hand, the image buffer data may be returned to the upper level image application program for a UI access. At the same time, the image data within the crop range can be automatically written into the bitmap file while searching for the bottom line of the scanned image. The width of the meaningful image regions can be determined by computing the distance between the position of a leftmost start pixel and the position of a rightmost end pixel of a meaningful image region first appeared in a partial image block. The width computed is transferred back to the scanner so as to reset the width for reading the subsequent image data. The length of the scanned image cannot be determined until a bottom line is found.
To find the bottom line, for each meaningful image region, sample a plurality of line areas to determine if the meaningful image region contains the bottom line. For each meaningful image region examined, sum up the total number of image lines until the bottom line is reached. Eventually, for non-UI access, when the bottom line is found, the size of the scanned image is also determined. For TWAIN UI access, the parameter indicating the end of image data is transferred to the upper level image application program. The whole process is performed in real-time and without the process of prescan. The present invention can efficiently save the scan time because it only reads the desired image data after finding the width of the scanned image and can stop scanning right after a bottom line of the scanned image is found. Consequently, if the scanned image is a 3xc3x975 photo, the scanner will stop right after finishing reading the image of the 3xc3x975 photo.